package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.Result;
import com.dongdongshop.pojo.itemCat.TbItemCat;
import com.dongdongshop.service.itemCat.ItemCatService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("itemCat")
public class ItemCatController {
    @Reference
    private ItemCatService itemCatService;
    private final Logger logger = LoggerFactory.getLogger(ItemCatController.class);
    //动态查询分类
    @RequestMapping("listItemCat")
    @ResponseBody
    public Result listItemCat(Long parentId){
        try {
            List<TbItemCat> list = itemCatService.listItemCat(parentId);
            return Result.ok().setData(list);
        }catch (Exception e){
            logger.error("动态查询分类失败",e);
            return Result.fail();
        }

    }
    //根据Id查询分类
    @RequestMapping("getItemCat")
    @ResponseBody
    public Result getItemCat(Long id){
        try {
            TbItemCat itemCat = itemCatService.getItemCatById(id);
            return Result.ok().setInfo(itemCat);

        }catch (Exception e){
            logger.error("回显分类失败",e);
            return Result.fail();
        }
    }

}
